<?php
if ($msg != "default") echo $msg_output; 
if ($action == "view") {
$query_ids = "SELECT * FROM users";
if ($row_user['userLevel'] <= "2") $query_ids .= " WHERE userLevel='1' OR userLevel='2' ORDER BY lastName ASC"; 
else {
	$id = $row_user['id'];
	$query_ids .= " WHERE id='$id'";
} 
$ids = mysql_query($query_ids, $connection) or die(mysql_error());
$row_ids = mysql_fetch_assoc($ids);
$totalRows_ids = mysql_num_rows($ids);
}

if ($action == "edit") {
$query_edit = "SELECT * FROM users WHERE id='$id'";
$edit = mysql_query($query_edit, $connection) or die(mysql_error());
$row_edit = mysql_fetch_assoc($edit);
}

?>
<?php if ($action == "view") { ?>
<p><span class="icon"><img src="images/arrow_left.png" border="0" align="absmiddle" /></span><a href="<?php echo $_SERVER['HTTP_REFERER']; ?>">Back to Previous</a></p>
<?php 
if ($totalRows_ids > 0) {
if ($row_user['userLevel'] == "1") { ?>
<p><span class="icon"><img src="images/user_add.png" border="0" align="absmiddle" /></span><a href="index.php?section=id&action=add">Add an Instructional Designer?</a></p>
<?php } ?>
<table class="dataTable">
<tr>
	<th>Name</th>
    <th width="13%">User Name</th>
    <th width="26%">Email</th>
    <th width="13%">Phone</th>
    <th width="26%">Course(s) in Process</th>
    <th width="13%">Actions</th>
</tr>
<?php 
do { 
$query_courses = sprintf("SELECT * FROM courses WHERE did='%s' AND course_complete='N'", $row_ids['id']); 
$courses = mysql_query($query_courses, $connection) or die(mysql_error());
$row_courses = mysql_fetch_assoc($courses);
$totalRows_courses = mysql_num_rows($courses);
?>
<tr style="background-color: <?php echo $color; ?>">
	<td nowrap="nowrap"><?php echo $row_ids['firstName']." ".$row_ids['lastName']; ?></td>
    <td class="data"><?php echo $row_ids['user_name']; ?></td>
    <td class="data"><?php echo $row_ids['email']; ?></td>
    <td class="data"><?php echo $row_ids['phone']; ?></td>
    <td class="data"><?php do { if ($row_courses['did'] == $row_user['id']) { echo "<a href='index.php?section=view_proposal&cid=".$row_courses['id']."'>"; } echo $row_courses['jiu_course_id']; if ($row_courses['did'] == $row_user['id']) { echo "</a>"; echo "&nbsp;&nbsp;"; } } while ($row_courses = mysql_fetch_assoc($courses)); ?></td>
    <td class="data">
    <?php if (($row_ids['user_name'] == $_SESSION['loginUsername']) || ($row_user['userLevel'] == "1")) { ?>
    <span class="icon"><img src="images/pencil.png" border="0" align="absmiddle" /></span><a href="index.php?section=id&action=edit&id=<?php echo $row_ids['id']; ?>">Edit Info</a>
    <br />
    <span class="icon"><img src="images/key.png" border="0" align="absmiddle" /></span><a href="index.php?section=id&action=edit&go=password&id=<?php echo $row_ids['id']; ?>">Change Password</a>
	<?php } 
	if (($row_user['userLevel'] == "1")  && ($row_ids['user_name'] != $_SESSION['loginUsername'])) { ?>
    <?php if ($row_ids['userLevel'] != "1") { ?>
    <br />
    <span class="icon"><img src="images/user_edit.png" border="0" align="absmiddle" /></span><a href="javascript:confirmation('includes/process.inc.php?section=id&dbTable=users&action=make_admin&go=1','id','<?php echo $row_ids['id']; ?>','Are you sure you want to make <?php echo $row_ids['firstName']." ".$row_ids['lastName']; ?> an Admin?');">Make Admin</a><?php } else { ?><br /><span class="icon"><img src="images/cross.png" border="0" align="absmiddle" /></span><a href="javascript:confirmation('includes/process.inc.php?section=id&dbTable=users&action=make_admin&go=2','id','<?php echo $row_ids['id']; ?>','Are you sure you want to remove Admin privledges for <?php echo $row_ids['firstName']." ".$row_ids['lastName']; ?>?');">Remove Admin</a><?php } ?>
	<br />
	<span class="icon"><img src="images/bin_closed.png" border="0" align="absmiddle" /></span><a href="javascript:confirmation('includes/process.inc.php?dbTable=users&action=delete','id','<?php echo $row_ids['id']; ?>','Are you sure you want to delete <?php echo $row_ids['firstName']." ".$row_ids['lastName']; ?>?');">Delete</a>
	<?php } ?>
    </td>
</tr>
<?php if ($color == $color1) { $color = $color2; } else { $color = $color1; } ?>
<?php } while ($row_ids = mysql_fetch_assoc($ids)); ?>
</table>
<?php } 
else { echo "<div class='error_msg'>There are no Instructional Designers in the Database."; if ($row_user['userLevel'] <= "2") echo " <a href='index.php?section=id&action=add'>Add one?</a>"; echo "</div>"; }
}
if (($action == "add") || ($action == "edit") && ($go == "default")) { ?>
<p>
<span class="icon"><img src="images/arrow_left.png" border="0" align="absmiddle" /></span><a href="<?php echo $_SERVER['HTTP_REFERER']; ?>">Back to Previous</a>
</p>
<p>
<span class="icon"><img src="images/arrow_left.png" border="0" align="absmiddle" /></span><a href="index.php?section=id&action=view">Back to  <?php if ($row_user['userLevel'] <= "2") echo "Instructional Designers List"; else echo "My Information"; ?></a>
</p>
<table class="dataTable">
<tr style="background-color: <?php echo $color1; ?>">
	<td class="dataLabel">First Name:</td>
    <td class="data"><input name="firstName" type="text" size="30" value="<?php if ($action == "edit") echo $row_edit['firstName']; ?>" /></td>
</tr>
<tr style="background-color: <?php echo $color2; ?>">
	<td class="dataLabel">Last Name:</td>
    <td class="data"><input name="lastName" type="text" size="30" value="<?php if ($action == "edit") echo $row_edit['lastName']; ?>" /></td>
</tr>
<tr style="background-color: <?php echo $color1; ?>">
	<td class="dataLabel">Phone:</td>
    <td class="data"><input name="phone" type="text" size="30" value="<?php if ($action == "edit") echo $row_edit['phone']; ?>" /></td>
</tr>
<tr style="background-color: <?php echo $color2; ?>">
	<td class="dataLabel">Email Address:</td>
    <td class="data"><input name="email" type="text" size="30" value="<?php if ($action == "edit") echo $row_edit['email']; ?>" /></td>
</tr>
<input name="userLevel" type="hidden" value="2" />
<?php  if (($row_user['userLevel'] <= "2") && ($action == "add")) { ?>
<tr style="background-color: <?php echo $color2; ?>">
	<td class="dataLabel">Password:</td>
    <td class="data"><input name="password" type="text" size="30" value="" /></td>
</tr>
<?php } 
if ($row_user['userLevel'] <= "2") { 
?>

<tr style="background-color: <?php echo $color1; ?>">
	<td class="dataLabel">User Name (No Spaces):</td>
    <td class="data"><input name="user_name" type="text" size="30" value="<?php if ($action == "edit") echo $row_edit['user_name']; ?>" /></td>
</tr>
<?php } ?>
</table>
<?php } 
if (($action == "edit") && ($go == "password") && (($row_user['userLevel'] <= "2") || ($row_user['user_name'] == $_SESSION["loginUsername"]))) { ?>
<p>
<span class="icon"><img src="images/arrow_left.png" border="0" align="absmiddle" /></span><a href="<?php echo $_SERVER['HTTP_REFERER']; ?>">Back to Previous</a>
</p>
<p>
<span class="icon"><img src="images/arrow_left.png" border="0" align="absmiddle" /></span><a href="index.php?section=id&action=view">Back to <?php if ($row_user['userLevel'] <= "2") echo "Instructional Designers List"; else echo "My Information"; ?></a>
</p>
<table class="dataTable">
<tr style="background-color: <?php echo $color1; ?>">
	<td class="dataLabel">New Password:</td>
    <td class="data"><input name="password" type="text" size="30" value="" /></td>
</tr>
</table>
<?php } ?>
<?php if (($action == "add") || ($action == "edit")) { ?>
<p style="margin-top: 1.25em;"><input id="Submit" name="Submit" type="submit" class="button" value="<?php if ($action == "edit") echo "Update"; else echo "Submit"; ?>"></p>
<?php } ?>